import { apiUrl } from "@api/index";
import type {DatasetEntry, ListDatasetEntriesParam, CreateDatasetEntryParam, UpdateDatasetEntryParam, DeleteDatasetEntryParam} from "@store/entity/dataset/entry";
import { get, post, put, del, ToUrlSearchParams, type Paged } from "@util/http";

export const listPagedDatasetEntriesBuild = (datasetCode: string) => {
  return async (val: ListDatasetEntriesParam): Promise<Paged<DatasetEntry>> => {
    return await get<Paged<DatasetEntry>>(apiUrl(`/dataset/${datasetCode}/entry`), ToUrlSearchParams(val), { auth: true });
  };
};

export const getDatasetEntryBuild = (datasetCode: string) => {
  return async (id: number): Promise<DatasetEntry> => {
    return await get<DatasetEntry>(apiUrl(`/dataset/${datasetCode}/entry/${id}`));
  }
};

export const createDatasetEntryBuild = (datasetCode: string) => {
  return async (val: CreateDatasetEntryParam): Promise<DatasetEntry> => {
    return await post<DatasetEntry>(apiUrl(`/dataset/${datasetCode}/entry`), val);
  }
};

export const updateDatasetEntryBuild = (datasetCode: string) => {
  return async (val: UpdateDatasetEntryParam): Promise<DatasetEntry> => {
    return await put<DatasetEntry>(apiUrl(`/dataset/${datasetCode}/entry/${val.id}`), val);
  }
};

export const deleteDatasetEntryBuild = (datasetCode: string) => {
  return async (val: DeleteDatasetEntryParam): Promise<DatasetEntry> => {
    return await del<DatasetEntry>(apiUrl(`/dataset/${datasetCode}/entry/${val.id}`));
  }
};